import asyncio
import functools
import os
import time
from concurrent.futures import ThreadPoolExecutor
from async_threading import async_timed
import requests


def get_status_code(url):
    response = requests.get(url)
    return response.status_code


@async_timed()
async def main():
    loop = asyncio.get_running_loop()
    with ThreadPoolExecutor(max_workers=os.cpu_count() + 4) as pool:
        urls = ["http://www.baidu.com" for _ in range(100)]
        tasks = [loop.run_in_executor(pool, functools.partial(get_status_code, url)) for url in urls]
        result = await asyncio.gather(*tasks)
        print(result)


asyncio.run(main())
